//
//  RegisterView.m
//  Diary
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 王艺拓. All rights reserved.
//

#import "RegisterView.h"

@implementation RegisterView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addRegisterView];
        [self setUpGesture];
    }
    return self;
}

- (void)addRegisterView{
    // 用户名
    self.registerUserTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.frame)*0.1, CGRectGetHeight(self.frame)*0.35, CGRectGetWidth(self.frame)*0.8, CGRectGetWidth(self.frame)*0.1)];
    UIImageView *userLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.registerUserTextField.frame), CGRectGetHeight(self.registerUserTextField.frame))];
    userLeft.image = [UIImage imageNamed:@"login_icon"];
    self.registerUserTextField.leftView = userLeft;
    self.registerUserTextField.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:self.registerUserTextField];
    UIView *userLineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.registerUserTextField.frame), CGRectGetMaxY(self.registerUserTextField.frame), CGRectGetWidth(self.registerUserTextField.frame), 2)];
    userLineView.backgroundColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.25 alpha:1];
    //[self addSubview:userLineView];
    
    // 密码
    self.registerPasswordTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.registerUserTextField.frame), CGRectGetMaxY(self.registerUserTextField.frame)+CGRectGetHeight(self.registerUserTextField.frame)*0.3, CGRectGetWidth(self.registerUserTextField.frame), CGRectGetHeight(self.registerUserTextField.frame))];
    UIImageView *passwordLeft = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.registerPasswordTextField.frame), CGRectGetHeight(self.registerPasswordTextField.frame))];
    passwordLeft.image = [UIImage imageNamed:@"password_icon"];
    self.registerPasswordTextField.leftView = passwordLeft;
    self.registerPasswordTextField.leftViewMode = UITextFieldViewModeAlways;
    self.registerPasswordTextField.secureTextEntry = YES;
    [self addSubview:self.registerPasswordTextField];
    UIView *passwordLineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.registerPasswordTextField.frame), CGRectGetMaxY(self.registerPasswordTextField.frame), CGRectGetWidth(self.registerPasswordTextField.frame), 2)];
    passwordLineView.backgroundColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.25 alpha:1];
    //[self addSubview:passwordLineView];
    
    // 再次输入密码
    self.registerAgainTextField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.registerPasswordTextField.frame), CGRectGetMaxY(self.registerPasswordTextField.frame)+CGRectGetHeight(self.registerPasswordTextField.frame)*0.3, CGRectGetWidth(self.registerPasswordTextField.frame), CGRectGetHeight(self.registerPasswordTextField.frame))];
    UIImageView *againLeftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.registerAgainTextField.frame), CGRectGetHeight(self.registerAgainTextField.frame))];
    againLeftView.image = [UIImage imageNamed:@"password_icon"];
    self.registerAgainTextField.leftView = againLeftView;
    self.registerAgainTextField.leftViewMode = UITextFieldViewModeAlways;
    self.registerAgainTextField.secureTextEntry = YES;
    [self addSubview:self.registerAgainTextField];
    UIView *againLineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.registerAgainTextField.frame), CGRectGetMaxY(self.registerAgainTextField.frame), CGRectGetWidth(self.registerAgainTextField.frame), 2)];
    againLineView.backgroundColor = [UIColor colorWithRed:0.25 green:0.25 blue:0.25 alpha:1];
    [self addSubview:againLineView];
    
    
    // 注册按钮
    self.registerFinishButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //self.registerFinishButton.frame = CGRectMake(CGRectGetWidth(self.frame)*0.3, CGRectGetHeight(self.frame)*0.63, CGRectGetWidth(self.frame)*0.1, CGRectGetWidth(self.frame)*0.1);
    
    self.registerFinishButton.frame = CGRectMake(CGRectGetMaxX(self.registerAgainTextField.frame) - CGRectGetWidth(self.frame)*0.1*2, CGRectGetMaxY(self.registerAgainTextField.frame), CGRectGetWidth(self.frame)*0.1*2, CGRectGetWidth(self.frame)*0.1*2);
    
    
    [self.registerFinishButton setImage:[UIImage imageNamed:@"confirming"] forState:UIControlStateNormal];
    [self addSubview:self.registerFinishButton];
    
    // 登录按钮
    self.registerCancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.registerCancelButton.frame = CGRectMake(CGRectGetMaxX(self.registerFinishButton.frame)+CGRectGetWidth(self.frame)*0.1, CGRectGetMinY(self.registerFinishButton.frame), CGRectGetWidth(self.registerFinishButton.frame), CGRectGetHeight(self.registerFinishButton.frame));
        
    self.registerCancelButton.frame = CGRectMake(CGRectGetMinX(self.registerAgainTextField.frame), CGRectGetMaxY(self.registerAgainTextField.frame), CGRectGetWidth(self.frame)*0.1*2, CGRectGetWidth(self.frame)*0.1*2);
    
    [self.registerCancelButton setImage:[UIImage imageNamed:@"cancelingLeft"] forState:UIControlStateNormal];
    [self addSubview:self.registerCancelButton];
    
    
}


- (void)setUpGesture{
    UISwipeGestureRecognizer *swipedown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedown:)];
    swipedown.direction = UISwipeGestureRecognizerDirectionDown;
    [self addGestureRecognizer:swipedown];
}

- (void)swipedown:(UISwipeGestureRecognizer *)sender{
    [self.registerUserTextField resignFirstResponder];
    [self.registerPasswordTextField resignFirstResponder];
    [self.registerAgainTextField resignFirstResponder];
}


@end
